package 题目集.hash;

import java.util.BitSet;
import java.util.Scanner;

public class 水体 {
    static int maxN = 100001;
    static int[] count = new int[maxN];
    static int k;
    static int n;
    static int res;
    static int[][] nums;   //压缩一下,0位置存值，1位置存次数
    static int cnt;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextInt();
        BitSet set = new BitSet();
        for (int i = 0; i < n; i++) {
            int v = sc.nextInt();
            set.set(v);
            count[v]++;
        }
        if (k == 0) {
            System.out.println(set.stream().count());
            return;
        } else {
            nums = new int[set.size()][2];
            set.stream().forEach(v -> {
                nums[cnt][0] = v;
                nums[cnt++][1] = count[v];
            });
            res=dfs(0,-1);
        }
        System.out.println(res);
    }

    //选i和不选i能达到的最大值,可以改dp
    public static int dfs(int i, int p) {
        if (i == cnt) return 0;
        if (nums[i][0] == p) {
            return dfs(i + 1, p);
        }
        int dfs1 = dfs(i + 1, p);    //不选当前
        int dfs2 = dfs(i + 1, nums[i][0] + k) + nums[i][1];    //选当前
        return Math.max(dfs1, dfs2);
    }
}
